package study.Lambda2;

import java.util.HashMap;
import java.util.Map;

public class CaculateMap {
    private static Map<String, Caculate> caculateMap = new HashMap<>();

    public CaculateMap() {
        caculateMap.put("add", this::add);
        caculateMap.put("multiply", this::multiply);
        caculateMap.put("subtract", this::subtract);
        caculateMap.put("round", (a, b) -> round(a, b));
    }

    public int add(int a, int b)
    {
        return a + b;
    }

    public int multiply(int a, int b)
    {
        return a * b;
    }

    public int subtract(int a, int b){
        return a - b;
    }

    public int round(int a, int b){
        return a / b;
    }

    public int caculate(String operation, int a, int b)
    {
        return caculateMap.get(operation).caculate(a, b);
    }
}
